<!--
 * @Author: your name
 * @Date: 2022-03-29 10:13:00
 * @LastEditTime: 2022-03-29 10:21:39
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \geyao\geyao\纯函数220329.html
-->
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>纯函数</title>
	</head>
	<body>
		<script>
			//    函数的返回结果只依赖于它的参数。
			//函数执行过程里面没有副作用。

			//第一条 函数的结果只能依赖他的参数  纯函数
			function animal(name) {
				console.log(this.name)
			}
			//第二条  不是纯函数
			var father = 'father'
			function animal(name) {
				console.log(this.name + 'father')
			}

			//第三步 改变了外层的对象 不是纯函数
			const a = 1
			const foo = (obj, b) => {
				obj.x = 2
				return obj.x + b
			}
			const counter = { x: 1 }
			foo(counter, 2) // => 4
			counter.x // => 2
		</script>
	</body>
</html>
